var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1,
    showBl: false,
    showBl2: false,
    isHidden:true
  },

  // 切换类名on
  tab: function (e) {
    const eIndex = e.currentTarget.dataset.index;
    this.setData({
      num: eIndex
    });
    if (eIndex==3){
      this.setData({
        isHidden: false
      });
    }else{
      this.setData({
        isHidden: true
      });
    }
  },

  // 拨打电话
  hotLine: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.order.sendMobile
    })
  },

  // 弹出押金弹窗（送车）
  show: function () {
    this.setData({
      showBl: true
    })
  },

  // 隐藏押金弹窗（送车）
  hide: function () {
    this.setData({
      showBl: false
    })
  },

  // 弹出押金弹窗（还车）
  show2: function () {
    this.setData({
      showBl2: true
    })
  },

  // 隐藏押金弹窗（还车）
  hide2: function () {
    this.setData({
      showBl2: false
    })
  },
  sendRemarkInput: function (e) {
    this.setData({
      sendRemark: e.detail.value
    })
  },
  receiveRemarkInput: function (e) {
    this.setData({
      receiveRemark: e.detail.value
    })
  },
  realDepositAmountInput:function(e){
    this.setData({
      realDepositAmount: e.detail.value
    })
  },
  // 送车完成成功弹窗
  showModal: function () {
    let that=this
    wx.showModal({
      title: '提示',
      confirmColor: '#008cf8',
      content: '确定送车完成？',
      success: function (res) {
        if (res.confirm) {
          var depositStatus=that.data.num
          var sendRemark = that.data.sendRemark
          var realDepositAmount = that.data.realDepositAmount
          if (depositStatus == 3 && util.isBlank(realDepositAmount)){
            wx.showToast({
              title: '请输入金额',
              icon: 'none',
              duration: 1500
            })
            return
          }
          if (util.isBlank(sendRemark)) {
            wx.showToast({
              title: '请填写备注',
              icon: 'none',
              duration: 1500
            })
            return
          }
          wx.request({
            url: 'https://small.qiongyazuche.com/sunday/small/order/sendOrder',
            method: 'POST',
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            data: {
              'orderId': that.data.order.id,
              'depositStatus': depositStatus,
              'sendRemark': sendRemark,
              'realDepositAmount': realDepositAmount
            },
            success: function (res) {
              if (res.data.code == -1){
                wx.showToast({
                  title: '系统异常',
                  icon: 'none',
                  duration: 1500
                })
              }else{
                wx.switchTab({
                  url: '../my-order/my-order'
                })
              }
             
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  // 还车完成成功弹窗
  showModal2: function () {
    let that = this
    wx.showModal({
      title: '提示',
      confirmColor: '#008cf8',
      content: '确定核销完成？',
      success: function (res) {
        if (res.confirm) {
          var receiveRemark = that.data.receiveRemark
     
          if (util.isBlank(receiveRemark)) {
            wx.showToast({
              title: '请填写备注',
              icon: 'none',
              duration: 1500
            })
            return
          }
          wx.request({
            url: 'https://small.qiongyazuche.com/sunday/small/order/receiveOrder',
            method: 'POST',
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            data: {
              'orderId': that.data.order.id,
              'receiveRemark': receiveRemark
            },
            success: function (res) {
              if (res.data.code == -1) {
                wx.showToast({
                  title: '系统异常',
                  icon: 'none',
                  duration: 1500
                })
              } else {
                wx.switchTab({
                  url: '../my-order/my-order'
                })
              }

            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let orderId = options.orderId
    let that = this
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/order/findOne',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        'orderId': orderId
      },
      success: function (res) {
        that.setData({
          order: res.data.result
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '琼崖租车',
      path: '/pages/index/index'
    }
  }
})